<template>
  <c-dialog ref="dialog" :open-fun="openFun" title="激活验收任务">
    <c-list ref="form" :model="formData" :rules="formRules" label-width="120px">
      <c-list-item label="验收任务激活原因" prop="activationReason">
        <el-input v-model="formData.activationReason" maxlength="1024" type="textarea" show-word-limit :autosize="{minRows:3}" placeholder="验收任务激活原因" clearable />
      </c-list-item>
      <c-list-item>
        <div class="btn-container">
          <c-button @click="cancelHandle">取消</c-button>
          <c-button type="primary" @click="confirmHandle">确定</c-button>
        </div>
      </c-list-item>
    </c-list>
  </c-dialog>
</template>
<script>
import { postActiveTask } from '@/api/check'
export default {
  name: 'ActiveCheckTask',
  props: {
    selData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      formData: {
        activationReason: ''
      },
      formRules: {
        activationReason: [{ required: true, message: '请输入验收任务激活原因', trigger: 'change' }]
      }
    }
  },
  computed: {
    detail() {
      return this.selData.length > 0 ? this.selData[0] : {}
    }
  },
  methods: {
    openFun() {
      if (!this.singleJudge(this.selData, '激活验收任务', true)) {
        return false
      }
      // 只有对门店建设项目号“是否完结”值为“否”，验收任务进度值为“已结案”，
      // 且结案类型为“未验收结案”的数据，可操作此按钮，
      // 否则提示：仅”未验收结案“，且门店建设未完结的数据操作此按钮
      if (this.detail.acceptSchedule === 'L' && this.detail.acceptEndType === 'NO_CHECK') {
        return true
      }
      this.$message.warning('仅"未验收结案"，且门店建设未完结的数据操作此按钮！')
      return false
    },
    confirmHandle() {
      return this.$refs.form.validate().then(() => {
        // console.log(this.formData)
        const data = {
          acceptSchedule: this.detail.acceptSchedule,
          isEnd: this.detail.isEnd,
          id: this.detail.id,
          acceptEndType: this.detail.acceptEndType,
          activationReason: this.formData.activationReason
        }
        return postActiveTask(data).then(res => {
          this.$message.success('操作成功！')
          this.$emit('on-success')
          this.$refs.dialog.visible = false
        })
      })
    },
    cancelHandle() {
      this.$refs.dialog.visible = false
    }
  }
}
</script>
